<?php
/**
 * Created by PhpStorm.
 * User: krystal
 * Date: 2019/6/26
 * Time: 14:28
 */

namespace app\common\lib;

use app\common\cachemodel\FortuneRecodeBack;
use app\common\cachemodel\MapLinePlanetInfo;
use app\common\cachemodel\MapRecodeBack;
use app\common\cachemodel\MapUnlockResult;
use app\common\cachemodel\MonthFortune;
use app\common\cachemodel\Orders as OrdersCacheModel;
use app\common\cachemodel\Rectification as RectificationModel;
use app\common\cachemodel\YearFortune;
use app\common\lib\astrolog\Acg;
use app\common\lib\exception\ApiException;
use app\common\model\Orders;
use app\common\cachemodel\Recode;
use Exception;
use think\Cache;
use think\Env;
use think\Log;
use XznsTools\cache\CacheManage;

class PushQueue
{
    /**
     * 组合校准生辰入队数据，并加入队列
     * @param $reid
     * @param $oid
     * @param $out_trade_no
     * @return bool
     * @throws Exception
     */
    public function Rectification($userInfo, $reid, $oid, $out_trade_no)
    {
        try
        {
            $RectificationCacheModel = new RectificationModel();
            $rectification = $RectificationCacheModel->getRecDetail([$reid]);
            if ($rectification)
            {
                //将生时矫正改为等待矫正状态
                $RectificationCacheModel->saveRec($userInfo['id'] ?? 0, $reid, ['status' => 1]);

                $rectification = $rectification ? current($rectification) : [];
                $event_array = [];
                foreach ($rectification['events'] as $event)
                {
                    $event['time'] = strtotime($event['time']);
                    $event_array[] = $event;
                }
                $recode = (new Recode())->getInfoById($rectification['rid']);
                $queueConfig = config('queue');
                $jobData = [
                    'oid' => $oid,
                    'order_id' => $out_trade_no,
                    'reid' => $reid,
                    'start_time' => $rectification['start_time'],
                    'end_time' => $rectification['end_time'],
                    'events' => $event_array,
                    'recode' => $recode,
                    'push_switch' => $queueConfig['push_switch'],
                ];
                if (Util::getVips($userInfo['id'] ?? 0, 1, 0))
                {
                    $queueConfig['rectification_delay'] = 0;
                }
                queuePush($queueConfig['rectification_task'], $jobData, $queueConfig['rectification_queue'], $queueConfig['rectification_delay']);
            }
        }
        catch (Exception $e)
        {
            Log::write('校准生辰入队失败错误信息：' . $e->getMessage() . '【' . $e->getFile() . $e->getLine() . '】', 'error');
            return false;
        }
        return true;
    }

    /**
     * 组合运势入队数据，并加入队列
     * @param $map
     * @return bool|mixed
     * @throws Exception
     */
    public function Fortune($map)
    {
        $oid = $map['oid'];

        $where = ['o.id' => $oid, 'o.gid' => ['in', config('goods.month_year_id')]];

        try
        {
            $fortune = (new Orders())->alias('o')
                ->field('f.time,f.type,f.rids,g.expire_time,o.status,o.gid,o.uid,o.order_id,o.order_type,o.env_type,o.id,o.extend')
                ->join('wechat_backup_07_18_14_43_00.app_goods g', 'o.gid=g.id')
                ->join('wechat_backup_07_18_14_43_00.app_fortune f', 'o.fid=f.id')
                ->where($where)
                ->findOrFail()
                ->toArray();
        }
        catch (Exception $e)
        {
            $fortune = [];
        }

        if (!empty($fortune))
        {
            $rids = explode(',', $fortune['rids']);
            $start_time = $fortune['time'];
            $end_time = strtotime($fortune['expire_time'], $fortune['time']);

            $recode_info = [];
            foreach ($rids as $rid)
            {
                //获取档案信息
                $recode_info[$rid] = (new Recode())->getInfoById($rid);
            }
            switch ($fortune['type'])
            {
                case 2:
                    $start_time = date('Y-m', $start_time);
                    $end_time = date('Y-m', strtotime('-1 months', $end_time));
                    break;
                case 3:
                    $start_time = date('Y', $start_time);
                    $end_time = date('Y', strtotime('-1 years', $end_time));
                    break;
                default:
                    $start_time = '';
                    $end_time = '';
                    break;
            }
            $extend = isset($fortune['extend']) && $fortune['extend'] ? json_decode($fortune['extend'], true) : [];
            $version = $extend['app_info']['version'] ?? '';
            $unlock_time = prDates1(['start' => $start_time, 'end' => $end_time, 'type' => $fortune['type']]);
            try
            {
                $fortuneLockData = [];
                //将运势加入队列运算
                switch ($fortune['type'])
                {
                    case 2:
                        $fname = 'month';
                        $isSimpleness = $fortune['order_type'] == 12 ? 1 : 0;
                        // 写入待解锁数据
                        $monthFortneModel = new MonthFortune();
                        foreach ($rids as $rid)
                        {
                            $recodeData = [
                                'id' => $rid,
                                'name' => $recode_info[$rid]['name'],
                                'type' => $recode_info[$rid]['type'],
                                'year' => $recode_info[$rid]['year'],
                                'month' => $recode_info[$rid]['month'],
                                'day' => $recode_info[$rid]['day'],
                                'hour' => $recode_info[$rid]['hour'],
                                'minute' => $recode_info[$rid]['minute'],
                                'timezone' => $recode_info[$rid]['timezone'],
                                'birth_country' => $recode_info[$rid]['birth_country'],
                                'birth_province' => $recode_info[$rid]['birth_province'],
                                'birth_city' => $recode_info[$rid]['birth_city'],
                                'live_country' => $recode_info[$rid]['live_country'],
                                'live_province' => $recode_info[$rid]['live_province'],
                                'live_city' => $recode_info[$rid]['live_city'],
                                'long_deg' => $recode_info[$rid]['long_deg'],
                                'long_min' => $recode_info[$rid]['long_min'],
                                'ew' => $recode_info[$rid]['ew'],
                                'lat_deg' => $recode_info[$rid]['lat_deg'],
                                'lat_min' => $recode_info[$rid]['lat_min'],
                                'ns' => $recode_info[$rid]['ns'],
                                'avatar' => $recode_info[$rid]['avatar'],
                                'is_summer' => $recode_info[$rid]['is_summer'],
                                'uid' => $recode_info[$rid]['uid'],
                                'isself' => $recode_info[$rid]['isself'],
                            ];
                            $backRid = (new FortuneRecodeBack())->insertGetId(['rid' => $rid, 'recode_info' => \GuzzleHttp\json_encode($recodeData, JSON_UNESCAPED_UNICODE)]);
                            foreach ($unlock_time as $month)
                            {
                                $recodeUniqueKey = "{$recode_info[$rid]['type']}:{$recode_info[$rid]['year']}:{$recode_info[$rid]['month']}:{$recode_info[$rid]['day']}:{$recode_info[$rid]['hour']}:{$recode_info[$rid]['minute']}:{$recode_info[$rid]['timezone']}:{$recode_info[$rid]['ew']}:{$recode_info[$rid]['long_deg']}:{$recode_info[$rid]['long_min']}:{$recode_info[$rid]['ns']}:{$recode_info[$rid]['lat_deg']}:{$recode_info[$rid]['lat_min']}:{$recode_info[$rid]['is_summer']}";
                                $resMonthFortune = $monthFortneModel->batchGetRecodeFortuneMonthInfo($rid, [$month], [$recodeUniqueKey], $isSimpleness);
                                $cacheKey = $rid . ':' . $month . ($isSimpleness === 1 ? ':1' : '');
                                if ($resMonthFortune && isset($resMonthFortune[$cacheKey][$recodeUniqueKey]) && $resMonthFortune[$cacheKey][$recodeUniqueKey])
                                {
                                    $monthForData = \GuzzleHttp\json_decode(current($resMonthFortune)[$recodeUniqueKey], true);
                                    if ($monthForData['type'] == 0)
                                    {
                                        $updateData = [
                                            'type' => 1,
                                            'order_id' => $fortune['order_id'],
                                            'status' => 1,
                                            'rid_back' => $backRid,
                                        ];

                                        $monthFortneModel->where('id', $monthForData['id'])->update($updateData);

                                        CacheManage::getInstance()->setCacheConfig('fortune.fortune_month')
                                            ->setCacheKeyDetail('details_v2', $cacheKey)
                                            ->rmCache('details_v2');
                                        continue;
                                    }
                                }

                                CacheManage::getInstance()->setCacheConfig('fortune.fortune_month')
                                    ->setCacheKeyDetail('details_v2', $cacheKey)
                                    ->rmCache('details_v2');

                                $fortuneLockData[] = [
                                    'type' => 1,
                                    'is_simpleness' => $isSimpleness,
                                    'order_id' => $fortune['order_id'],
                                    'rid_back' => $backRid,
                                    'status' => 1,
                                    'rid' => $rid,
                                    'month' => $month,
                                ];
                            }
                        }
                        if ($fortuneLockData)
                        {
                            $monthFortneModel->saveAll($fortuneLockData);
                        }
                        foreach ($rids as $rid)
                        {
                            CacheManage::getInstance()
                                ->setCacheConfig('fortune.fortune_month')
                                ->setCacheKeyDetail('list_v2', $rid . ':' . $isSimpleness)
                                ->rmCache('list_v2');
                        }
                        break;
                    case 3:
                        $fname = 'year';
                        // 写入待解锁数据
                        foreach ($rids as $rid)
                        {
                            $recodeData = [
                                'id' => $rid,
                                'name' => $recode_info[$rid]['name'],
                                'type' => $recode_info[$rid]['type'],
                                'year' => $recode_info[$rid]['year'],
                                'month' => $recode_info[$rid]['month'],
                                'day' => $recode_info[$rid]['day'],
                                'hour' => $recode_info[$rid]['hour'],
                                'minute' => $recode_info[$rid]['minute'],
                                'timezone' => $recode_info[$rid]['timezone'],
                                'birth_country' => $recode_info[$rid]['birth_country'],
                                'birth_province' => $recode_info[$rid]['birth_province'],
                                'birth_city' => $recode_info[$rid]['birth_city'],
                                'live_country' => $recode_info[$rid]['live_country'],
                                'live_province' => $recode_info[$rid]['live_province'],
                                'live_city' => $recode_info[$rid]['live_city'],
                                'long_deg' => $recode_info[$rid]['long_deg'],
                                'long_min' => $recode_info[$rid]['long_min'],
                                'ew' => $recode_info[$rid]['ew'],
                                'lat_deg' => $recode_info[$rid]['lat_deg'],
                                'lat_min' => $recode_info[$rid]['lat_min'],
                                'ns' => $recode_info[$rid]['ns'],
                                'avatar' => $recode_info[$rid]['avatar'],
                                'is_summer' => $recode_info[$rid]['is_summer'],
                                'uid' => $recode_info[$rid]['uid'],
                                'isself' => $recode_info[$rid]['isself'],
                            ];
                            $backRid = (new FortuneRecodeBack())->insertGetId(['rid' => $rid, 'recode_info' => \GuzzleHttp\json_encode($recodeData, JSON_UNESCAPED_UNICODE)]);
                            foreach ($unlock_time as $year)
                            {
                                $fortuneLockData[] = [
                                    'type' => 1,
                                    'order_id' => $fortune['order_id'],
                                    'rid_back' => $backRid,
                                    'year' => $year,
                                    'rid' => $rid,
                                    'status' => 1,
                                    'version' => $version,
                                ];

                                // 年运缓存删除
                                CacheManage::getInstance()->setCacheConfig('fortune.fortune_year')
                                    ->setCacheKeyDetail('details_v2', $rid . ':' . $year)
                                    ->rmCache('details_v2');
                            }
                        }

                        if ($fortuneLockData)
                        {
                            (new YearFortune())->saveAll($fortuneLockData);
                            foreach ($rids as $rid)
                            {
                                CacheManage::getInstance()
                                    ->setCacheConfig('fortune.fortune_year')
                                    ->setCacheKeyDetail('list_v2', $rid)
                                    ->rmCache('list_v2');
                            }
                        }
                        break;
                    default :
                        $fname = '';
                        break;
                }
                if ($fname != '')
                {
                    $this->fortune_queue($fortune, $recode_info, $unlock_time, 1, $version);
                }
            }
            catch (Exception $e)
            {
                Log::write($fortune['type'] . '运势入队失败错误信息。' . $e->getMessage() . '文件信息:' . $e->getFile() . ':' . $e->getLine(), 'error');
                return false;
            }
            return $fortune['type'];
        }
        return true;
    }

    /**
     * 运势入队
     * @param $orders
     * @param $recode_info
     * @param $unlock_time
     * @param int $unlock_type 解锁类型 1=>订单解锁 2=>系统赠送
     * @param string $version
     * @throws Exception
     */
    public function fortune_queue($orders, $recode_info, $unlock_time, $unlock_type = 1, $version = '')
    {
        $queueConfig = config('queue');
        $orderType = (int)$orders['order_type'];
        // 运势队列消费时需要的数据
        $jobData = [
            'oid' => (int)$orders['id'],
            'order_id' => $orders['order_id'],
            'unlock_type' => $unlock_type, // 解锁类型 1=>订单解锁 2=>系统赠送
            'recode' => $recode_info,
            'start_time' => $unlock_time,
            'type' => in_array($orderType, [3, 12]) ? 'month' : 'year',
            'status' => 1,
            'push_switch' => $orderType === 12 ? false : $queueConfig['push_switch'], // 精简版月运 不推送消息
            'version' => $version,
        ];
        if (Env::get('host.name') !== 'online')
        {
            $queueConfig['fortune_new_delay'] = 0;
        } elseif (Util::getVips(current($recode_info)['uid'], $orders['order_type'], 0))
        {
            $queueConfig['fortune_new_delay'] = 0;
        }
        $fortuneDelay = ((int)$orders['order_type'] === 12 || in_array($orders['env_type'], [2, 7], false)) ? 0 : $queueConfig['fortune_new_delay']; // 精简版月运 和微信小程序解锁取消延时
        queuePush($queueConfig['fortune_new_task'], $jobData, $queueConfig['fortune_new_queue'], $fortuneDelay);
    }

    /**
     * 幸运之城入队前的逻辑处理
     * @param string $order_id
     * @param bool $isNewOrder true=>新订单需要添加备份档案等数据，false=>旧订单需要更新备份档案等数据
     * @param int[] $mapUnlockResultUpdateData
     * @return bool
     */
    public function Map($order_id, $isNewOrder = true, $mapUnlockResultUpdateData = ['status' => 1]): bool
    {
        $OrdersCacheModel = new OrdersCacheModel();
        //获取当前档案已付款的命运之城的订单
        try
        {
            $MpaOrder = $OrdersCacheModel->alias('o')
                ->join('wechat_backup_07_18_14_43_00.app_orders_goods og', 'o.id=og.oid')
                ->where(['o.order_id' => $order_id])
                ->order('o.id', 'DESC')
                ->field('o.order_id,o.id oid,o.status,o.uid,og.rid,og.gid')
                ->select();
            $MpaOrder = json_decode(json_encode($MpaOrder, true), true);
            $gids = array_column($MpaOrder, 'gid');
        }
        catch (Exception $e)
        {
            $MpaOrder = [];
        }
        if ($MpaOrder)
        {
            try
            {
                $orderData = current($MpaOrder);
                $orderData['order_id'] = $order_id;
                $RecodeInfo = (new Recode())->getInfoById($orderData['rid']); //获取当前档案的信息
                $linePlanetInfo = (new Acg())->getPlanetInfo($RecodeInfo);//获取所有行星数据信息
                //todo 获取城市排行指数
                //todo 获取地点具体影响
                if ($isNewOrder)
                {
                    $line_planet_info_id = (new MapLinePlanetInfo())->saveData(['rid' => $orderData['rid'], 'line_planet_info' => json_encode($linePlanetInfo, true)]);//添加解锁的幸运线行星数据
                    $rid_back = (new MapRecodeBack())->saveData(['rid' => $orderData['rid'], 'recode_info' => json_encode($RecodeInfo, true)]);//档案备份
                    $result = [];
                    foreach ($MpaOrder as $map_order)
                    {
                        if (in_array($map_order['gid'], [18, 19, 105], false))
                        {
                            $status = 1;
                        } else
                        {
                            $status = 2;
                        }
                        $result[] = ['type' => 1, 'order_id' => $order_id, 'rid' => $map_order['rid'], 'gid' => $map_order['gid'], 'status' => $status, 'rid_back' => $rid_back, 'line_planet_info_id' => $line_planet_info_id];
                    }
                    //添加解锁结果信息
                    (new MapUnlockResult())->saveData($result);
                } else
                {
                    $unlockIds = (new MapUnlockResult())->getUnlockIdsFromCache(1, $order_id);
                    $unlockInfo = (new MapUnlockResult())->getInfoById(current($unlockIds), ['rid_back', 'line_planet_info_id']);
                    (new MapLinePlanetInfo())->updateData($unlockInfo['line_planet_info_id'], ['line_planet_info' => json_encode($linePlanetInfo, true)]);//更新解锁的幸运线行星数据
                    (new MapRecodeBack())->updateData($unlockInfo['rid_back'], ['recode_info' => json_encode($RecodeInfo, true)]);//更新档案备份
                    (new MapUnlockResult())->updateData($unlockIds, $mapUnlockResultUpdateData);//更新解锁结果信息
                }
                //队列处理
                if (array_intersect([18, 19, 105], $gids))
                {
                    $this->map_queue($MpaOrder, $RecodeInfo);
                }
            }
            catch (Exception $e)
            {
                Log::write('幸运之城入队失败' . $e->getMessage() . '错误行数：' . $e->getLine(), 'error');
                return false;
            }
        }
        return true;
    }

    /**
     * 地图队列处理
     * @param $MpaOrder
     * @param $RecodeInfo
     * @throws Exception
     */
    public function map_queue($MpaOrder, $RecodeInfo)
    {
        $OrdersCacheModel = new OrdersCacheModel();
        $orderData = current($MpaOrder);
        //添加入队数据
        $unlockGids = array_column($MpaOrder, 'gid');
        if (array_intersect([18, 19, 105], $unlockGids))
        {
            $queueConfig = config('queue');
            $jobData = [
                'id' => $orderData['oid'],
                'order_id' => $orderData['order_id'],
                'uid' => (int)$orderData['uid'],
                'rid' => (int)$orderData['rid'],// 档案id
                'rname' => $RecodeInfo['name'],
                'sex' => $RecodeInfo['type'],// 档案性别
                'isself' => $RecodeInfo['isself'],
                'longitude' => ($RecodeInfo['long_deg'] + $RecodeInfo['long_min'] / 60) * $RecodeInfo['ew'],// 用户出生地经度
                'latitude' => ($RecodeInfo['lat_deg'] + $RecodeInfo['lat_min'] / 60) * $RecodeInfo['ns'],// 用户出生地纬度
                'time' => strtotime($RecodeInfo['year'] . '-' . $RecodeInfo['month'] . '-' . $RecodeInfo['day'] . ' ' . $RecodeInfo['hour'] . ':' . $RecodeInfo['minute'])
                    - ($RecodeInfo['timezone'] + $RecodeInfo['is_summer']) * 3600,// 用户出生时间
                'data_type' => 1,
                'push_switch' => $queueConfig['push_switch'],
            ];

            if (Util::getVips($orderData['uid'], 5, $orderData['rid']))
            {
                $queueConfig['map_delay'] = 0;
            }
            //订单入队
            queuePush($queueConfig['map_task'], $jobData, $queueConfig['map_queue'], $queueConfig['map_delay']);
            //删除订单缓存,将订单状态改为计算中
            if ($orderData['status'] == 4)
            {
                $OrdersCacheModel->UpdateData($orderData['order_id'], ['status' => 1], 1);
                //设置幸运之城按钮显示为计算中
                Cache::set($orderData['uid'] . ':' . $orderData['rid'] . '_acg_logic_status', 1);
            }
        }//若当前订单未购买命运之城,则直接状态更改为计算完成
        else
        {
            //更新2.0订单缓存
            $OrdersCacheModel->UpdateData($orderData['order_id'], ['status' => 4], 4);
        }
    }

    /**
     * 检测订单关闭入队
     * @param $order_id
     * @param int $delayTime
     * @throws ApiException
     */
    public static function CloseOrder($order_id, $delayTime = 0): void
    {
        if ($delayTime === 0)
        {
            $queueConfig = config('queue');
            $delayTime = $queueConfig['close_order']['delay'];
        }
        Util::queuePush('close_order', ['order_id' => $order_id], $delayTime);
    }

    /**
     * 组合本命预测入队数据，并加入队列
     * @param int $uid
     * @param int $rid
     * @param array $unlcok_gids 解锁商品id
     * @param string $order_id
     * @param null|bool $pushSwitch 推送开关
     * @param null|int $queueDelay 队列等待时长
     * @return bool
     * @throws Exception
     */
    public function NatalReport($uid, $rid, $unlcok_gids, $order_id, $pushSwitch = null, $queueDelay = null)
    {
        $queueConfig = config('queue');
        //获取档案信息
        $recode = (new Recode())->getInfoById($rid);
        //内部vip无队列延迟
        if (Util::getVips($uid, 7, $rid))
        {
            $queueConfig['natal_report_delay'] = 0;
        }
        $jobData = [
            'uid' => $uid,
            'recode' => $recode,
            'unlock_gids' => $unlcok_gids,
            'order_id' => $order_id,
            'push_switch' => is_null($pushSwitch) ? $queueConfig['push_switch'] : $pushSwitch, // 为null时取配置推送开关
        ];

        if (Util::getVips($uid, 7, 0))
        {
            $natalReportQueueDelay = 0;
        } else
        {
            $natalReportQueueDelay = is_null($queueDelay) ? $queueConfig['natal_report_delay'] : $queueDelay;
        }

        //订单入队
        queuePush($queueConfig['natal_report_task'], $jobData, $queueConfig['natal_report_queue'], $natalReportQueueDelay);
        return true;
    }

    /**
     * 定制报告加入失效队列(包含审核时间，自定义问题后台审核通过后再入队),think_queue入队
     * @param $question
     * @param $type
     * @param $jobData
     */
    public function customReportInvalid($question, $type, $jobData)
    {
        $queueConfig = config('queue');
        switch ($type)
        {
            case 1://接单超时
//                //16:00 - 23:59 第二天八点计算失效
//                //00:00 - 7:59获取当天八点计算失效
//                $queue_task = $queueConfig['custom_report_received_task'];
//                $queue_dalay = $queueConfig['custom_report_received_delay'];
//                $queue_queue = $queueConfig['custom_report_received_queue'];
//                //若当前是接单队列且是自定义问题，则退出需后台审核通过后重新入队
//                if ((int)$question['qtype'] === 2)
//                {
//                    return;
//                }
//                $re = $this->getCustomqueueDelayTime($question['pay_time'], $queue_dalay);
//                if ($re !== false)
//                {
//                    $queue_dalay = $re;
//                }
//                queuePush($queue_task, $jobData, $queue_queue, $queue_dalay);

                $queue_task6 = $queueConfig['custom_report_answer6_task'];
                $queue_dalay6 = $queueConfig['custom_report_answer6_delay'];
                $queue_queue6 = $queueConfig['custom_report_answer6_queue'];
                queuePush($queue_task6, $jobData, $queue_queue6, $queue_dalay6); // 24个小时未完成
                break;
            case 2://回答超时
                $queue_task = $queueConfig['custom_report_answer4_task'];
                $queue_dalay = $queueConfig['custom_report_answer4_delay'];
                $queue_queue = $queueConfig['custom_report_answer4_queue'];
                queuePush($queue_task, $jobData, $queue_queue, $queue_dalay); // 4个小时未首次提交
                break;
            case 3://评论超时
                $queue_task = $queueConfig['custom_report_comment_task'];
                $queue_dalay = $queueConfig['custom_report_comment_delay'];
                $queue_queue = $queueConfig['custom_report_comment_queue'];
                queuePush($queue_task, $jobData, $queue_queue, $queue_dalay);
                break;
            case 4:// 指定咨询师 12小时后未完成
                $queue_task = $queueConfig['custom_report_astr_success_task'];
                $queue_dalay = $queueConfig['custom_report_astr_success_delay'];
                $queue_queue = $queueConfig['custom_report_astr_success_queue'];
                queuePush($queue_task, $jobData, $queue_queue, $queue_dalay);
                break;
            default:
        }
    }

    /**
     * 获取定制报告延迟后入队时间
     * @param $payTime
     * @param $queueDelay
     * @return false|int
     */
    protected function getCustomqueueDelayTime($payTime, $queueDelay)
    {
        if ($payTime)
        {
            $pay_time = date('G', $payTime);//获取当前支付的小时
            if ($pay_time >= 16 && $pay_time <= 23)
            {
                $toTime = strtotime(date('Y-m-d 08:00:00', strtotime('+1day', $payTime)));//获取第二天八点的时间戳
                $queue_dalay = $toTime - $payTime + $queueDelay;
            } elseif ($pay_time >= 0 && $pay_time < 8)
            {
                $toTime = strtotime(date('Y-m-d 08:00:00', $payTime));//获取第二天八点的时间戳
                $queue_dalay = $toTime - $payTime + $queueDelay;
            }
        }
        return $queue_dalay ?? false;
    }

    public function SynastryReport(int $uid, int $synastryReportId, $rid1, $queueDelay = null)
    {
        $queueConfig = config('queue');
        //内部vip无队列延迟
        if (Util::getVips($uid, 17, $rid1))
        {
            $queueConfig['natal_report_delay'] = 0;
        }

        $jobData = [
            'synastry_report_id' => $synastryReportId,
            'push_switch' => $queueConfig['push_switch'], // 为null时取配置推送开关
        ];
        if (Util::getVips($uid, 17, 0))
        {
            $natalReportQueueDelay = 0;
        } else
        {
            $natalReportQueueDelay = is_null($queueDelay) ? $queueConfig['synastry_report_delay'] : $queueDelay;
        }
        //订单入队
        queuePush($queueConfig['synastry_report_task'], $jobData, $queueConfig['synastry_report_queue'], $natalReportQueueDelay);
        return true;
    }


    /**
     * 直播消息入队
     * @param array $data
     * @param int $delay
     * @throws ApiException
     */
    public static function LiveMsg($data = [], $delay = 0): void
    {
        Util::queuePush('live_msg', $data, $delay);
    }
}
